package com.jinmdz.fmis.core.base;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.jinmdz.fmis.core.constant.EResultCode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * result基类
 *
 * @author LiCongLu
 * @date 2019-12-20 09:34
 */
@ApiModel(value = "请求响应结果对象", description = "此对象只返回结果及信息，并返回数据")
public class BaseResult<T> extends BaseBean {
    /**
     * 响应结果值
     * 具体值可参考EResultCode枚举类
     */
    @ApiModelProperty(value = "响应结果值,0请求失败；1请求成功；2会话失效", name = "code", example = "0/1/2", position = 1)
    private int code;

    /**
     * 具体结果信息，用服务端提示
     */
    @ApiModelProperty(value = "结果信息", name = "message", position = 2)
    private String message;

    /**
     * 备注信息
     */
    @JsonIgnore
    @ApiModelProperty(value = "备注信息", name = "remark", position = 3)
    private String remark;

    /**
     * 响应数据
     */
    @ApiModelProperty(value = "响应数据", name = "data", position = 5)
    private T data;

    public BaseResult() {
    }

    public BaseResult(EResultCode resultCode) {
        this.setResultCode(resultCode);
    }

    public int getCode() {
        return code;
    }

    public BaseResult setCode(int code) {
        this.code = code;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public BaseResult setMessage(String message) {
        this.message = message;
        return this;
    }

    public String getRemark() {
        return remark;
    }

    public BaseResult setRemark(String remark) {
        this.remark = remark;
        return this;
    }

    public T getData() {
        return data;
    }

    public BaseResult setData(T data) {
        this.data = data;
        return this;
    }

    /**
     * 重设枚举值
     *
     * @param resultCode 枚举值
     * @return
     */
    public BaseResult setResultCode(EResultCode resultCode) {
        return this.setCode(resultCode.getCode()).setMessage(resultCode.getMessage());
    }
}
